package com.atguigu.job;

import com.atguigu.client.SearchFeignClient;
import com.atguigu.client.UserFeignClient;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class DispatchHandler {
    @Autowired
    private SearchFeignClient searchFeignClient;

    //定时执行热门专辑更新任务
    @XxlJob("updateHotAlbumJob")
    public void updateHotAlbumJob() {

        log.info("定时执行热门专辑更新");
        searchFeignClient.updateRanking();
    }

    @Autowired
    private UserFeignClient userFeignClient;
    //定时执行会员状态更新任务
    @XxlJob("updateUserVIPStatusJob")
    public ReturnT updateUserVIPStatusJob() {
        try {
            String jobParam = XxlJobHelper.getJobParam();
            log.info("定时执行会员状态:{}",jobParam);
            userFeignClient.updateVipExpireStatus();
            return ReturnT.SUCCESS;
        } catch (Exception e) {
            return ReturnT.FAIL;
        }
    }
}
